import '../../util/_base_export.dart';
import '../../util/_view_export.dart';

import 'package:tudouapp/blocs/cart.dart';

import 'package:flutter_stripe_payment/flutter_stripe_payment.dart';
import 'package:tobias/tobias.dart';
import 'package:fluwx/fluwx.dart' as fluwx;

import '../../util/app_util.dart';

class OrderCheckoutScreen extends StatefulWidget {
  OrderCheckoutScreen({Key? key}) : super(key: key);
  _OrderCheckoutScreenState createState() => _OrderCheckoutScreenState();
}

class _OrderCheckoutScreenState extends State<OrderCheckoutScreen> {
  final _stripePayment = FlutterStripePayment();

  late CancelFunc cancelLoading;

  @override
  void initState() {
    super.initState();
    stripeInit();
  }

  stripeInit() async {
    await _stripePayment.setStripeSettings(App3rdKey.stripe_key, App3rdKey.applepay_id);
    print(_stripePayment);
  }

  @override
  Widget build(BuildContext context) {
    _confirm() async {
      print('bbb');
      AppSession.bottomIndex = 2;
      Provider.of<CartBloc>(context, listen: false)..clear();
      App.router.navigateTo(context, AppRoutes.appMain, replace: true);
      // Navigator.pushNamedAndRemoveUntil(context, '/', (_) => false);
      // Navigator.of(context).popUntil(ModalRoute.withName('/app_main'));
    }

    return Consumer<CartBloc>(
      builder: (context, _cart, child) => Builder(
        builder: (context) {
          return Scaffold(
            appBar: AppBar(
              brightness: Brightness.light,
              leading: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  Navigator.pop(context);
                },
                child: Container(
                  child: Icon(
                    Icons.chevron_left,
                    color: AppColor.blackMain,
                    size: 32,
                  ),
                ),
              ),
              title: Text('结账', style: TextStyle(color: AppColor.blackMain)),
            ),
            body: SingleChildScrollView(
              child: Container(
                color: Color(0xffF4F4F4),
                child: Column(
                  children: <Widget>[
                    (_cart.ticket['attach_order'] ?? {}).isNotEmpty
                        ? _addOrderBlock(_cart)
                        : Container(),
                    _cardAddressBlock(_cart),
                    SizedBox(height: 6.h),
                    _deliveryTimeBlock(_cart),
                    Divider(
                      color: Color(0xffcAcAcA),
                      height: 1.0,
                      indent: 0.0,
                      endIndent: 0.0,
                    ),
                    _paymentMethodBlock(_cart),
                    Divider(
                      color: Color(0xffcAcAcA),
                      height: 1.0,
                      indent: 0.0,
                      endIndent: 0.0,
                    ),
                    _commentBlock(_cart),
                    Divider(
                      color: Color(0xffcAcAcA),
                      height: 1.0,
                      indent: 0.0,
                      endIndent: 0.0,
                    ),
                    _outOfStockBlock(_cart),
                    Divider(
                      color: Color(0xffcAcAcA),
                      height: 1.0,
                      indent: 0.0,
                      endIndent: 0.0,
                    ),
                    _voucherBlock(_cart),
                    Divider(
                      color: Color(0xffcAcAcA),
                      height: 1.0,
                      indent: 0.0,
                      endIndent: 0.0,
                    ),
                    _summaryBlock(_cart),
                    SizedBox(height: 6.h),
                    _itemListBlock(_cart),
                    SizedBox(
                      height: 88.h,
                    ),
                  ],
                ),
              ),
            ),
            floatingActionButton: Container(
              // padding: EdgeInsets.symmetric(horizontal: 20),

              height: 80.h,
              width: ScreenUtil().screenWidth,
              child: RaisedButton(
                color: AppColor.yellowMain,
                onPressed: () async {
                  var lv_pmid = '';
                  if ((_cart.ticket['payment_cards'] ?? {})
                      .isNotEmpty) if ((_cart.ticket['payment_cards']['2'] ?? {}).isNotEmpty)
                    lv_pmid = _cart.ticket['payment_cards']['2']['pmid'];
                  if ((lv_pmid.isEmpty) && (_cart.ticket['payment_channel'] == 2)) {
                    AppPopupService.showAlertSimple('E', '信息错误', '请先维护支付方式');
                  } else {
                    var lm_result = await _cart.checkoutSubmit();

                    if ((lm_result ?? {}).isNotEmpty) {
                      if (lm_result['charge_total'] == 0)
                        AppPopupService.showAlertSimple('S', '下单成功', '请到历史订单里查看',
                            confirm: _confirm);
                      else {
                        cancelLoading = BotToast.showLoading(duration: Duration(seconds: 10));
                        AppPopupService.showAlertSimple('W', '准备支付', '加载中.....',
                            iv_duration: Duration(seconds: 1));

                        switch (_cart.ticket['payment_channel']) {
                          case 2:
                            {
                              var intentResponse = await _stripePayment.confirmPaymentIntent(
                                  lm_result['payment_intent'],
                                  lv_pmid,
                                  lm_result['charge_total'],
                                  true);
                              switch (intentResponse.status) {
                                case PaymentResponseStatus.succeeded:
                                  {
                                    cancelLoading();
                                    AppPopupService.showAlertSimple('S', '下单成功', '请到历史订单里查看',
                                        confirm: _confirm);

                                    print(intentResponse.paymentIntentId);
                                    print(intentResponse);
                                  }
                                  break;
                                case PaymentResponseStatus.failed:
                                  {
                                    cancelLoading();
                                    AppPopupService.showAlertSimple('E', '支付失败', '请到历史订单里查看',
                                        confirm: _confirm);

                                    print(intentResponse);
                                    break;
                                  }
                                default:
                                  {
                                    cancelLoading();
                                    _confirm();
                                    print(intentResponse);
                                  }
                                  break;
                              }
                              break;
                            }

                          case 11:
                            {
                              Map payResult;
                              try {
                                print('aaa');
                                _confirm();
                                cancelLoading();
                                payResult = await aliPay(lm_result['payment_intent']);
                                print(payResult);
                              } on Exception catch (e) {
                                print(e);
                              }
                              break;
                            }
                          case 21:
                            {
                              // Map payResult;
                              try {
                                print('aaa');
                                _confirm();
                                cancelLoading();
                                var lm_intent = lm_result['payment_intent'];
                                fluwx
                                    .payWithWeChat(
                                  appId: lm_intent['appid'],
                                  partnerId: lm_intent['partnerid'],
                                  prepayId: lm_intent['prepayid'],
                                  packageValue: lm_intent['package'],
                                  nonceStr: lm_intent['noncestr'],
                                  timeStamp: int.parse(lm_intent['timestamp']),
                                  sign: lm_intent['sign'],
                                )
                                    .then((data) {
                                  print("---> $data");
                                });
                              } on Exception catch (e) {
                                print(e);
                              }
                              break;
                            }
                        }
                      }
                    }
                  }
                },
                child: Text(
                  '确认下单',
                  style: TextStyle(
                    fontSize: 18.sp,
                  ),
                ),
              ),
            ),
            floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          );
        },
      ),
    );
  }

// ----------------------------------- //

//------------------------------------//
  Widget _addOrderBlock(CartBloc ib_cart) {
    return Container(
        height: 280.h,
        width: 375.w,
        color: Color(0xffF4F4F4),
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(8.w)),
          ),
          padding: EdgeInsets.symmetric(horizontal: 27.w, vertical: 19.5.h),
          margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.h),
          height: 212.h,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Text(
                '追加订单成功，将与此订单合并',
                softWrap: true,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  fontSize: 14.sp,
                  color: Color(0xff149AFC),
                ),
              ),
              SizedBox(height: 18.h),
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Container(
                    width: 240.w,
                    child: Text(
                      '#' +
                          ib_cart.ticket['attach_order']['oid'].toString() +
                          ' | ' +
                          ib_cart.ticket['attach_order']['status_desc'],
                      softWrap: true,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: 14.sp,
                        color: Color(0xff000000),
                      ),
                    ),
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      var lv_detail =
                          Uri.encodeQueryComponent(jsonEncode(ib_cart.ticket['attach_order']));
                      App.router
                          .navigateTo(context, AppRoutes.historyDetail + '?detail=${lv_detail}');
                    },
                    child: Text(
                      '订单详情',
                      softWrap: true,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: 12.sp,
                        color: Color(0xff149AFC),
                      ),
                    ),
                  )
                ],
              ),
              SizedBox(height: 11.5.h),
              Divider(
                color: Color(0xffcAcAcA),
                height: 1.0,
                indent: 0.0,
                endIndent: 0.0,
              ),
              SizedBox(height: 11.5.h),
              Column(children: [
                Container(
                  width: 290.w,
                  child: Text(
                    ib_cart.ticket['is_pickup']==1?'自取时间：':'配送时间：' +
                        ib_cart.ticket['attach_order']['dl_date'] +
                        ' ' +
                        ib_cart.ticket['attach_order']['dl_window'],
                    softWrap: true,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 14.sp,
                      color: Color(0xff000000),
                    ),
                  ),
                ),
                SizedBox(height: 3.h),
                Container(
                  width: 290.w,
                  child: Text(
                    '总共: ' +
                        (ib_cart.ticket['attach_order']['items'] ?? []).length.toString() +
                        '件商品',
                    softWrap: true,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 14.sp,
                      color: Color(0xff000000),
                    ),
                  ),
                ),
                SizedBox(height: 3.h),
                Container(
                  width: 290.w,
                  child: Text(
                    '总价: \$' + ib_cart.ticket['attach_order']['charge_total'].toString(),
                    softWrap: true,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 14.sp,
                      color: Color(0xff000000),
                    ),
                  ),
                ),
                SizedBox(height: 16.h),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          AppPopup.popUpInfo();
                        },
                        child: Row(children: [
                          Icon(
                            // MaterialCommunityIcons.information,
                            Icons.insert_drive_file_rounded,
                            color: Color(0xff4E4E4E),
                          ),
                          SizedBox(width: 6.w),
                          Container(
                            width: 56.w,
                            child: Text(
                              '追单说明',
                              softWrap: true,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 12.sp,
                                color: Color(0xff4E4E4E),
                              ),
                            ),
                          ),
                        ])),
                    SizedBox(width: 122.5.w),
                    GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          AppPopup.popUpCancel();
                        },
                        child: Row(children: [
                          Icon(
                            Icons.cancel_outlined,
                            color: Color(0xffFF9F05),
                          ),
                          SizedBox(width: 6.w),
                          Container(
                            width: 56.w,
                            child: Text(
                              '取消追单',
                              softWrap: true,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 12.sp,
                                color: Color(0xffFF9F05),
                              ),
                            ),
                          ),
                        ]))
                  ],
                ),
              ])
            ],
          ),
        ));
  }

  Widget _itemComp(Map im_item) {
    return Container(
      height: 66.h,
      padding: EdgeInsets.symmetric(horizontal: 28.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              if ((im_item['image_url'] ?? '').isNotEmpty)
                Container(
                  width: 50.w,
                  height: 50.h,
                  child: CachedNetworkImage(
                    imageUrl: im_item['image_url'],
                    fit: BoxFit.cover,
                  ),
                ),
              Container(
                padding: EdgeInsets.only(left: 6.w),
                width: 200.w,
                child: Text(
                  im_item['name'] ?? '',
                  softWrap: true,
                  maxLines: 2,
                  overflow: TextOverflow.fade,
                ),
              ),
            ],
          ),
          Text('\$' + im_item['price'].toString() + 'x' + im_item['amount'].toString()),
        ],
      ),
    );
  }

  Widget _cardAddressBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          App.router.navigateTo(context, AppRoutes.accountAddrList);
        },
        child: Container(
          height: 140.h,
          padding: EdgeInsets.symmetric(horizontal: 28.w),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  _headerText('配送信息'),
                  Row(
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('修改', fontSize: 13),
                    ],
                  ),
                ],
              ),
              Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(right: 10.w),
                    child: Icon(
                      // MaterialCommunityIcons.clipboard_account,
                      LineIcons.paste,
                      color: AppColor.yellowText,
                    ),
                  ),
                  if (ib_cart.ticket.isNotEmpty)
                    if ((ib_cart.ticket['user_address'] ?? {}).isNotEmpty)
                      _headerText(ib_cart.ticket['user_address']['consignee_name'] ?? '',
                          fontSize: 13),
                ],
              ),
              Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(right: 10.w),
                    child: Icon(
                      // MaterialCommunityIcons.phone_in_talk,
                      Icons.phone_bluetooth_speaker,
                      color: AppColor.yellowText,
                    ),
                  ),
                  if (ib_cart.ticket.isNotEmpty)
                    if ((ib_cart.ticket['user_address'] ?? {}).isNotEmpty)
                      _headerText(ib_cart.ticket['user_address']['consignee_phone'] ?? '',
                          fontSize: 13),
                ],
              ),
              Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(right: 10.w),
                    child: Icon(
                      // MaterialCommunityIcons.map_marker_radius,
                      Icons.map_rounded,
                      color: AppColor.yellowText,
                    ),
                  ),
                  Container(
                    width: 260.w,
                    height: 20.h,
                    child: Builder(builder: (context) {
                      if (ib_cart.ticket.isNotEmpty) {
                        if ((ib_cart.ticket['user_address'] ?? {}).isNotEmpty)
                          return _headerText(ib_cart.ticket['user_address']['addr'], fontSize: 13);
                        else
                          return Container(width: 0.0, height: 0.0);
                      } else
                        return Container(width: 0.0, height: 0.0);
                    }),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _deliveryTimeBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          App.router.navigateTo(context, AppRoutes.orderTime);
        },
        child: Container(
          height: 80.h,
          padding: EdgeInsets.symmetric(horizontal: 28.w),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  _headerText('配送时间'),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('修改', fontSize: 13),
                    ],
                  ),
                ],
              ),
              if (ib_cart.ticket.isNotEmpty)
                _contentText(ib_cart.ticket['dl_date'] + ' ' + ib_cart.ticket['dl_window']),
            ],
          ),
        ),
      ),
    );
  }

  Widget _paymentMethodBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: Container(
        height: 80.h,
        padding: EdgeInsets.symmetric(horizontal: 28.w),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText('支付方式'),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    // _callStripeDialog(context, ib_cart);
                    App.router.navigateTo(context, AppRoutes.orderPaymentChannel);
                  },
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('修改', fontSize: 13),
                    ],
                  ),
                ),
              ],
            ),
            _contentText(ib_cart.findPaymentChannelDescr(ib_cart.ticket['payment_channel'])),
            // if ((ib_cart.ticket ?? {}).isNotEmpty)
            //   if (ib_cart.ticket['payment_cards']['2'] != null)
            //     _contentText(ib_cart.ticket['payment_cards']['2']['brand'] +
            //         ' ****' +
            //         ib_cart.ticket['payment_cards']['2']['last4']),
            // if ((ib_cart.ticket ?? {}).isNotEmpty)
            //   if (ib_cart.ticket['payment_cards']['2'] == null)
            //     _contentText('添加银行卡中的Postal/Zip，是您银行信息的Postal'),
          ],
        ),
      ),
    );
  }

  Widget _commentBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          App.router.navigateTo(context, AppRoutes.orderComment);
        },
        child: Container(
          height: 80.h,
          padding: EdgeInsets.symmetric(horizontal: 28.w),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  _headerText('备注'),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('修改', fontSize: 13),
                    ],
                  ),
                ],
              ),
              if (ib_cart.ticket.isNotEmpty) _contentText(ib_cart.ticket['comment']),
            ],
          ),
        ),
      ),
    );
  }

  Widget _outOfStockBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          App.router.navigateTo(context, AppRoutes.outofStock);
        },
        child: Container(
          height: 80.h,
          padding: EdgeInsets.symmetric(horizontal: 28.w),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  _headerText('如遇缺货'),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('修改', fontSize: 13),
                    ],
                  ),
                ],
              ),
              if (ib_cart.ticket.isNotEmpty)
                _contentText(ib_cart.ticket['outstock_options']
                        [ib_cart.ticket['selected_outstock_option']] ??
                    ''),
            ],
          ),
        ),
      ),
    );
  }

  Widget _voucherBlock(CartBloc ib_cart) {
    var lv_voucher_title = AppText.text['account_voucher_name'];
    if (AppSession.appUtil.vouchers.length > 0)
      lv_voucher_title =
          lv_voucher_title + ' - ' + AppSession.appUtil.vouchers.length.toString() + ' 张可用';

    return Container(
      color: Colors.white,
      child: Container(
        height: 80.h,
        padding: EdgeInsets.symmetric(horizontal: 28.w),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText(lv_voucher_title),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    App.router.navigateTo(context, AppRoutes.voucherList + '?scenario=ORDER');
                  },
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Icon(
                        // MaterialCommunityIcons.square_edit_outline,
                        Icons.edit,
                        color: AppColor.yellowText,
                      ),
                      _contentText('使用', fontSize: 13),
                    ],
                  ),
                ),
              ],
            ),
            // voucher
            // if ((ib_cart.ticket ?? {}).isNotEmpty)
            //   _contentText(ib_cart.ticket['comment']),
          ],
        ),
      ),
    );
  }

  Widget _summaryBlock(CartBloc ib_cart) {
    return Container(
      color: Colors.white,
      child: Container(
        // height: (90 * 3).h,
        padding: EdgeInsets.symmetric(horizontal: 28.w, vertical: 8.h),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText('Sub total:'),
                if (ib_cart.ticket.isNotEmpty)
                  _headerText(ib_cart.ticket['fees_detail']['pretax'].toStringAsFixed(2)),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText('Delivery Charge:'),
                if (ib_cart.ticket.isNotEmpty)
                  _headerText(ib_cart.ticket['fees_detail']['dlexp'].toStringAsFixed(2)),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText('Tax:'),
                if (ib_cart.ticket.isNotEmpty)
                  _headerText(ib_cart.ticket['fees_detail']['tax_total'].toStringAsFixed(2)),
              ],
            ),
            // VIP &  Vouvher
            if ((ib_cart.ticket['active_discounts'] ?? []).isNotEmpty)
              for (var ll_discount in ib_cart.ticket['active_discounts'])
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    _headerText(ll_discount['name']),
                    _contentText(
                      '-' + ll_discount['amount_off'].toStringAsFixed(2),
                    ),
                  ],
                ),

            // }),

            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                _headerText('Total:'),
                if (ib_cart.ticket.isNotEmpty)
                  _contentText(ib_cart.ticket['fees_detail']['charge_total'].toStringAsFixed(2)),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget _itemListBlock(CartBloc ib_cart) {
    return ListView.builder(
      primary: false,
      shrinkWrap: true,
      itemCount: ib_cart.items.length,
      itemBuilder: (BuildContext context, int index) {
        var _item = ib_cart.items[index];
        print(_item);
        return Column(
          children: <Widget>[
            _itemComp(_item),
            Divider(
              height: 1.0,
              indent: 20.0,
              endIndent: 20.0,
            ),
          ],
        );
      },
    );
  }

  Widget _headerText(
    String iv_str, {
    int fontSize = 15,
  }) {
    return Text(
      iv_str,
      softWrap: true,
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      style: TextStyle(
        fontSize: fontSize.sp,
        color: AppColor.blackMain,
      ),
    );
  }

  Widget _contentText(
    String iv_str, {
    int fontSize = 15,
    int maxLines = 3,
  }) {
    return Text(
      iv_str,
      softWrap: true,
      overflow: TextOverflow.fade,
      maxLines: maxLines,
      style: TextStyle(
        fontSize: fontSize.sp,
        color: AppColor.yellowText,
      ),
    );
  }
}
